package com.edu.bhu.admin.controller.admin;

import java.util.List;

import com.edu.bhu.admin.domain.BikImages;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.service.IBikImagesService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 图片Controller
 * 
 * @author heyinan
 * @date 2022-03-14
 */
@Controller
@RequestMapping("/admin/images")
public class BikImagesController extends BaseController
{
    private String prefix = "admin/images";

    @Autowired
    private IBikImagesService bikImagesService;

    @RequiresPermissions("admin:images:view")
    @GetMapping()
    public String images()
    {
        return prefix + "/images";
    }

    /**
     * 查询图片列表
     */
    @RequiresPermissions("admin:images:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BikImages bikImages)
    {
        startPage();
        List<BikImages> list = bikImagesService.selectBikImagesList(bikImages);
        return getDataTable(list);
    }

    /**
     * 导出图片列表
     */
    @RequiresPermissions("admin:images:export")
    @Log(title = "图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BikImages bikImages)
    {
        List<BikImages> list = bikImagesService.selectBikImagesList(bikImages);
        ExcelUtil<BikImages> util = new ExcelUtil<BikImages>(BikImages.class);
        return util.exportExcel(list, "图片数据");
    }

    /**
     * 新增图片
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图片
     */
    @RequiresPermissions("admin:images:add")
    @Log(title = "图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BikImages bikImages)
    {
        return toAjax(bikImagesService.insertBikImages(bikImages));
    }

    /**
     * 修改图片
     */
    @RequiresPermissions("admin:images:edit")
    @GetMapping("/edit/{imagesId}")
    public String edit(@PathVariable("imagesId") Long imagesId, ModelMap mmap)
    {
        BikImages bikImages = bikImagesService.selectBikImagesByImagesId(imagesId);
        mmap.put("bikImages", bikImages);
        return prefix + "/edit";
    }

    /**
     * 修改保存图片
     */
    @RequiresPermissions("admin:images:edit")
    @Log(title = "图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BikImages bikImages)
    {
        return toAjax(bikImagesService.updateBikImages(bikImages));
    }

    /**
     * 删除图片
     */
    @RequiresPermissions("admin:images:remove")
    @Log(title = "图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bikImagesService.deleteBikImagesByImagesIds(ids));
    }
}
